import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:nft_shop/my/page/set/details_web_page.dart';
import 'package:nft_shop/res/global.dart';
import 'package:nft_shop/widgets/load_image.dart';
import 'package:nft_shop/widgets/my_app_bar.dart';
import 'package:nft_shop/widgets/my_scroll_view.dart';
import 'package:package_info/package_info.dart';

class MyAboutUsPage extends StatefulWidget {
  const MyAboutUsPage({Key? key}) : super(key: key);

  @override
  _MyAboutUsPageState createState() => _MyAboutUsPageState();
}

class _MyAboutUsPageState extends State<MyAboutUsPage> {
  String versionStr = "";

  @override
  Future<void> initInfo() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    versionStr = packageInfo.version;
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    initInfo();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppBar(
        centerTitle: "关于我们",
      ),
      body: MyScrollView(
        children: [
          Container(
            height: 225,
            width: double.infinity,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                LoadAssetImage("logo", width: 76, height: 76,),
                SizedBox(height: 15,),
                Text(Global.AppName,
                  style: TextStyle(fontSize: 16, color: Global.kTheme.textPrimary6,fontFamily: Global.mySemiboldFont),),
                SizedBox(height: 3,),
                Text("Version ${versionStr}",
                  style: TextStyle(fontSize: 14, color: Global.kTheme.inputHint1),),
              ],
            ),
          ),
          MyAboutUsItem(title: "平台介绍",isTopLink: true, onTap: () => Get.to(DetailsWebPage(name: "平台介绍",)),),
        ],
        bottomButton: Container(
          margin: EdgeInsets.only(bottom: 25 + ScreenUtil.getBottomBarH(context)),
          child: Center(
            child: Text.rich(
                TextSpan(
                  children: [
                    TextSpan(text: "Copyright © 2022 ", style: TextStyle(color: Global.kTheme.textPrimary9,fontSize: 14)),
                    TextSpan(text: Global.AppName, style: TextStyle(color: Global.kTheme.textPrimary9,fontSize: 14)),
                    TextSpan(text: ". All rights", style: TextStyle(color: Global.kTheme.textPrimary9,fontSize: 14)),
                  ],
                )
            ),
          ),
        ),
      ),
    );
  }

}


class MyAboutUsItem extends StatelessWidget {
  final bool   isTopLink;
  final String title;
  final GestureTapCallback? onTap;

  MyAboutUsItem({required this.title,this.onTap,this.isTopLink = false});

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: onTap,
      child: Container(
        height: 57,
        decoration: BoxDecoration(
            border: isTopLink?Border(
              bottom: Divider.createBorderSide(context, width: 1,color: Global.kTheme.colorLine),
              top: Divider.createBorderSide(context, width:1,color: Global.kTheme.colorLine),
            ):Border(
              bottom: Divider.createBorderSide(context, width: 1,color: Global.kTheme.colorLine),
            )
        ),
        margin: const EdgeInsets.only(left: 14.0),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Padding(
              padding: const EdgeInsets.only(left: 6),
              child: Text(title,style: TextStyle(fontFamily: Global.mySemiboldFont,fontSize: 14,color: Global.kTheme.textPrimary8),),
            ),
            Padding(
              padding: const EdgeInsets.only(right: 20),
              child: LoadAssetImage("next_icon",width: 7,height: 12,),
            )
          ],
        ),
      ),
    );
  }
}
